home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Languguage OS 2
/
Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO
/
language
/
parallax
/
ibm_pc_o.exe
/
SAMPLES
/
REALPIC.P
< prev
next >
Wrap
Text File
|
1992-11-06
|
29KB
|
877 lines
SYSTEM Evaluation_of_real_Random_Stereo_Images ; (* Version 1.0 *)
TYPE
string = ARRAY[ 200 ] OF CHAR ;
CONST
maxWidth = 64 ; (* maximal Width of input image *)
maxHeigth = 64 ; (* maximal Heigth of input image *)
maxDepth = 8 ; (* depth of computation *)
margin = 2 ;
Filter_iterat = 2 ;
CONFIGURATION
picture [ 1 .. maxHeigth ] , [ 1 .. maxWidth ] ;
CONNECTION
left_port : picture[ i,j ] <-> picture[ i ,j-1 ].right_port ;
up_port : picture[ i,j ] <-> picture[ i-1,j ].down_port ;
SCALAR
LeftPicture ,
RightPicture : ARRAY [ 1 .. maxHeigth ] , [ 1 .. maxWidth ] OF INTEGER ;
(* memory for left and right image *)
i , j , (* counter *)
PicHeigth, (* Heigth of Inputimage *)
PicWidth : INTEGER ; (* Width of Inputimage *)
OutputFile,
InputFile,
FileName : string ; (* name of Inputfile *)
Batch : BOOLEAN ; (* flag for Batchmode *)
counter, (* for Batchmode necessary variables *)
Number_of_Lines,
RegionX,
RegionY : INTEGER ;
VECTOR
Pixel : ARRAY [ 1 .. maxDepth ] OF INTEGER ;
(* memory for each Image-plane *)
Heigth, (* to which plain belongs a pixel *)
Left, (* Pixel of left image *)
Right : INTEGER ; (* Pixel of right image *)
(************************* STRCAT *******************************************)
(* catenation of two strings *)
PROCEDURE strcat( SCALAR first , second : string ) : SCALAR string ;
SCALAR
i , j : INTEGER ;
BEGIN
i := 0 ; j := 0 ;
WHILE first[i] <> CHR(0) DO INC(i) ; END ;
WHILE second[j] <> CHR(0) DO
first[i] := second[j] ;
INC(j) ;INC(i) ;
END ;
first[i] := CHR(0) ;
RETURN first ;
END strcat ;
(************************** READPICTURE *************************************)
(* request Imagename, check Imagesize, possibly request Imagesection read *)
(* Imagedata into the scalar array's LeftPicture[][] and RightPicture[][]. *)
PROCEDURE ReadPicture() : SCALAR BOOLEAN ;
SCALAR
Character : CHAR ;
Heigth, Width : INTEGER ;
XPos, YPos : INTEGER ;
DeltaX, DeltaY : INTEGER ;
magic : string ;
color : INTEGER ;
BEGIN
PicHeigth := maxHeigth ;
PicWidth := maxWidth ;
IF NOT Batch THEN
WriteString( "Inputfile (without extension '.l.ppm' and '.r.ppm' ) : " ) ;
(* requesting Filename *)
ReadString( InputFile ) ;
END ;
FileName := strcat( InputFile , ".l.ppm" ) ;
OpenInput( FileName ) ; (* open File *)
IF Done THEN
ReadString( magic ) ;
ReadInt( Width ) ; (* reading Heigth and Width of image *)
ReadInt( Heigth ) ;
CloseInput ;
IF Heigth < PicHeigth THEN
PicHeigth := Heigth ;
END ; (* IF Heigth *)
IF Width < PicWidth THEN
PicWidth := Width ;
END ; (* IF Heigth *)
IF ( Heigth > PicHeigth ) OR ( Width > PicWidth ) THEN
IF NOT Batch THEN
WriteString( "Image too large. Please enter Image-Region : " ) ;
ReadInt( DeltaX ) ;
ELSE
DeltaX := RegionX ;
DeltaY := RegionY ;
END ; (* IF *)
IF DeltaX >= 0 THEN
IF NOT Batch THEN
WriteString( "Y-Verschiebung : " ) ;
ReadInt( DeltaY ) ;
END ; (* IF *)
DeltaY := ABS( DeltaY ) ;
IF ( Width - PicWidth ) < DeltaX THEN
DeltaX := Width - PicWidth ;
END ;
IF ( Heigth - PicHeigth ) < DeltaY THEN
DeltaY := Heigth - PicHeigth ;
END ;
ELSE (* Delta negativ : using default region *)
CASE ABS( DeltaX ) OF
1 : DeltaX := 0 ; DeltaY := Heigth - PicHeigth ; |
2 : DeltaX := (Width - PicWidth ) DIV 2 ; DeltaY := Heigth - PicHeigth ; |
3 : DeltaX := Width - PicWidth ; DeltaY := Heigth - PicHeigth ; |
4 : DeltaX := 0 ; DeltaY := (Heigth - PicHeigth) DIV 2 ; |
5 : DeltaX := (Width - PicWidth ) DIV 2 ; DeltaY := (Heigth - PicHeigth) DIV 2 ; |
6 : DeltaX := Width - PicWidth ; DeltaY := (Heigth - PicHeigth) DIV 2 ; |
7 : DeltaX := 0 ; DeltaY := 0 ; |
8 : DeltaX := (Width - PicWidth ) DIV 2 ; DeltaY := 0 ; |
9 : DeltaX := Width - PicWidth ; DeltaY := 0 ;
ELSE
WriteString("Incorrect region.") ; WriteLn ;
RETURN FALSE ;
END ; (* CASE ABS(DeltaX) *)
END ; (* IF DeltaX >= 0 *)
ELSE
DeltaX := 0 ; DeltaY := 0 ;
END ; (* IF (Heigth.. *)
OpenInput( FileName ) ;
ReadString( magic ) ;
ReadInt( Width ) ; Read( Character ) ; (* read Linefeed *)
ReadInt( Heigth ) ; Read( Character ) ; (* read Linefeed *)
ReadInt( color ) ; Read( Character ) ;
WriteString( "Reading left image ..." ) ; WriteLn ;
FOR YPos := 1 TO Heigth DO
FOR XPos := 1 TO Width DO
Read( Character ) ;
Read( Character ) ;
Read( Character ) ;
IF (DeltaY < YPos <= (DeltaY+PicHeigth)) AND (* check image region *)
(DeltaX < XPos <= (DeltaX+PicWidth)) THEN
LeftPicture[ YPos-DeltaY ][ XPos-DeltaX ] := ORD( Character ) ;
END ; (* IF *)
END ; (* FOR *)
END ; (* FOR *)
FileName := strcat( InputFile , ".r.ppm" ) ;
OpenInput( FileName ) ;
ReadString( magic ) ;
ReadInt( Width ) ; Read( Character ) ; (* read Linefeed *)
ReadInt( Heigth ) ; Read( Character ) ; (* read Linefeed *)
ReadInt( color ) ; Read( Character ) ;
WriteString( "Reading right image ..." ) ; WriteLn ;
FOR YPos := 1 TO Heigth DO
FOR XPos := 1 TO Width DO
Read( Character ) ;
Read( Character ) ;
Read( Character ) ;
IF (DeltaY < YPos <= (DeltaY+PicHeigth)) AND (* check image region *)
(DeltaX < XPos <= (DeltaX+PicWidth)) THEN
RightPicture[ YPos-DeltaY ][ XPos-DeltaX ] := ORD( Character ) ;
END ; (* IF *)
END ; (* FOR *)
END ; (* FOR *)
RETURN TRUE ;
ELSE
WriteString( "File not found." ) ; WriteLn ;
RETURN FALSE ;
END ;(* IF Done *)
END ReadPicture ;
(************************** Show_Plains *************************************)
(* This procedure display the result of each image-plain for possible *)
(* viewing after each calculating step *)
PROCEDURE Show_Plains ;
SCALAR
plain, x, y : INTEGER ;
PicPlain : ARRAY [ 1 .. maxHeigth ] , [ 1 .. maxWidth ] OF CHAR ;
(* memory of image-plain *)
VECTOR
picture_element : CHAR ;
BEGIN
IF NOT Batch THEN (* only for interactive mode *)
REPEAT
WriteString("Which plain do you want to see ? ( 1 .. ");
WriteInt( maxDepth , 1 ) ;
WriteString(" , 0 = no plain ) : ") ;
ReadInt( plain ) ;
IF 1 <= plain <= maxDepth THEN
PARALLEL
picture_element := CHR (0);
ENDPARALLEL;
PARALLEL [ 1 .. PicHeigth ] , [ 1 .. PicWidth ]
picture_element := CHR( Pixel[ plain ]+ORD('0') );
ENDPARALLEL ;
STORE( picture_element , PicPlain ) ;
WriteString("Image-Plain : ") ; WriteInt( plain , 1 ) ; WriteLn ;
FOR y := 1 TO PicHeigth DO
WriteString( PicPlain[y] ) ;
WriteLn ;
END ; (* FOR y *)
WriteLn ;
END ; (* IF 1 <= plain .. *)
UNTIL plain = 0 ;
END ; (* IF NOT Batch *)
END Show_Plains ;
(************************* Compute_Heigth ***********************************)
(* Computes the plain-number on which a pixel lies *)
PROCEDURE Compute_Heigth ;
SCALAR
plain : INTEGER ;
BEGIN
PARALLEL
Heigth := 0 ;
ENDPARALLEL;
PARALLEL [ 1 .. PicHeigth ] , [ 1 .. PicWidth ]
FOR plain := 1 TO maxDepth DO (* to which plain belongs a Pixel *)
IF Pixel[plain] = 1 THEN
Heigth := plain ;
END ; (* IF Pixel[ plain ] = 1 *)
END ; (* FOR *)
ENDPARALLEL ;
END Compute_Heigth ;
(************************* Show_All *****************************************)
(* This procedure display the results of all image-plains *)
PROCEDURE Show_All ;
SCALAR
x, y : INTEGER ;
Picture : ARRAY [ 1 .. maxHeigth ] , [ 1 .. maxWidth ] OF CHAR ;
(* Memory of the whole Image *)
VECTOR
picture_element : CHAR ;
BEGIN
IF NOT Batch THEN
PARALLEL
picture_element := CHR (0);
ENDPARALLEL;
PARALLEL [ 1 .. PicHeigth ] , [ 1 .. PicWidth ]
picture_element := CHR( ORD('0') + Heigth ) ;
ENDPARALLEL ;
STORE( picture_element , Picture ) ;
FOR y := 1 TO PicHeigth DO
WriteString( Picture[y] ) ;
WriteLn ;
END ; (* FOR y *)
WriteLn ;
END ; (* IF NOT Batch *)
END Show_All ;
(************************* PPM_Output ***************************************)
(* saving the resulting heigth-information, File Format is PPM *)
PROCEDURE PPM_Output ;
SCALAR
i, j , color,a,b : INTEGER ;
BEGIN
PARALLEL
STORE( Heigth , LeftPicture );
color := REDUCE.MAX(Heigth);
ENDPARALLEL;
OpenOutput( FileName ) ;
WriteString ( "P6" ) ; WriteLn ; (* RAWBIT option, not ASCII *)
WriteInt( PicWidth(*-2*margin*) , 1 ) ; WriteLn ; (* without vertical margins *)
WriteInt( PicHeigth(*-2*margin*) , 1 ) ; WriteLn ; (* without horizontal margins *)
WriteInt( color, 1) ; WriteLn ; (* maximum color-component value *)
FOR i := 1(*+margin*) TO PicHeigth(*-margin*) DO
FOR j := 1(*+margin*) TO PicWidth(*-margin*) DO (* saving pixel: *)
Write( CHR( LeftPicture[i,j] )) ; (* red value *)
Write( CHR( LeftPicture[i,j] )) ; (* green value *)
Write( CHR( LeftPicture[i,j] )) ; (* blue value *)
END ; (* FOR j *)
END ; (* FOR i *)
CloseOutput ;
END PPM_Output ;
(************************* Search_Edge **************************************)
(* This procedure replace the original-pictures with their edge-pictures. *)
(* The calculation rule: *)
(* EDGE := SQRT( (LB-RB)^2 + (DB-UB)^2 ), with LB,RB,DB and UB *)
(* representing the brightness left, right, up and down *)
PROCEDURE Search_Edge( VECTOR Pixel : INTEGER ) : VECTOR INTEGER ;
SCALAR
Minimum,
Maximum : INTEGER ;
VECTOR
Sum1,
Sum2,
Help,
Neighbour : INTEGER ;
Factor : REAL ;
BEGIN
WriteString("Computing edge-pictures ...") ; WriteLn ;
PROPAGATE.right_port( Pixel , Neighbour ) ;
(* get brightness from above and below *)
Sum1 := Neighbour + Pixel ;
PROPAGATE.left_port( Pixel , Neighbour ) ;
Sum1 := Sum1 + Neighbour ;
PROPAGATE.up_port( Sum1 , Sum2 ) ;
PROPAGATE.down_port( Sum1 ) ;
Help := (Sum1-Sum2)**2 ;
PROPAGATE.up_port( Pixel , Neighbour ) ;
(* get brightness from left and right *)
Sum1 := Neighbour + Pixel ;
PROPAGATE.down_port( Pixel , Neighbour ) ;
Sum1 := Sum1 + Neighbour ;
PROPAGATE.left_port( Sum1 , Sum2 ) ;
PROPAGATE.right_port( Sum1 ) ;
Pixel := TRUNC( Sqrt(FLOAT(Help + (Sum1-Sum2)**2)) ) ;
(* replacing orginal-picture with edge-picture *)
Minimum := REDUCE.MIN(Pixel) ;
Maximum := REDUCE.MAX(Pixel) ;
Factor := 16.0 / FLOAT( Maximum - Minimum ) ; (* grade of compression *)
Pixel := TRUNC(FLOAT(Pixel - Minimum) * Factor) ;
IF Pixel < 3 THEN
Pixel := 0 ;
END ;
RETURN Pixel ;
END Search_Edge ;
(************************** ParallelSum3x3 **********************************)
(* ParallelSum3x3 calculates the sum of certain elements in a 3x3 *)
(* size neighbourhood *)
PROCEDURE ParallelSum3x3( VECTOR my_number : INTEGER ) : VECTOR INTEGER ;
VECTOR
Sum,
shift_number : INTEGER ; (* number which is sending to the neighbours *)
BEGIN
Sum := my_number ; (* number of myself *)
PROPAGATE .right_port(my_number,shift_number) ;
(* sending pixelvalue to the right *)
Sum := Sum + shift_number ;
PROPAGATE .left_port(my_number,shift_number) ;
(* sending to the left *)
Sum := Sum + shift_number ;
my_number := Sum ; (* store calculated horizontal sum *)
PROPAGATE .up_port(my_number,shift_number) ;
(* sending intermediate result above *)
Sum := Sum + shift_number ;
PROPAGATE .down_port(my_number,shift_number) ;
(* sending below *)
Sum := Sum + shift_number ;
RETURN Sum ; (* return the calculating sum *)
END ParallelSum3x3 ;
(************************** Average *****************************************)
(* Calculates the average of a value (my_number) within a range specified *)
(* by expansion. There will be considered only values greater than zero. *)
PROCEDURE Average( VECTOR my_number : REAL ;
SCALAR Umgebung : INTEGER ) : VECTOR REAL ;
SCALAR
i : INTEGER ; (* counter *)
VECTOR
Sum_Count, (* counter for valid values *)
Count1,
Count2 : INTEGER ;
Sum, (* Sum in the region *)
shift_number1,
shift_number2 : REAL ; (* numbers for sending to the neighbours *)
BEGIN
shift_number1 := my_number ;
shift_number2 := my_number ;
Sum := my_number ; (* number of myself *)
Count1 := 0 ; Count2 := 0 ;
IF my_number > 0.0 THEN (* counting only values > 0.0 *)
Count1 := 1 ; Count2 := 1 ;
END ;
Sum_Count := Count1 ;
FOR i := 1 TO Umgebung DO
PROPAGATE .right_port(shift_number1) ; (* sending own pixelvalue to the *)
PROPAGATE .left_port (shift_number2) ; (* right and to the left *)
Sum := Sum + shift_number1 + shift_number2 ;
PROPAGATE .right_port(Count1) ; (* informing about validity of the values *)
PROPAGATE .left_port (Count2) ;
Sum_Count := Sum_Count + Count1 + Count2 ;
END ;
shift_number1 := Sum ; (* store the calculated horizontal sum *)
shift_number2 := Sum ; (* and sending above and below *)
Count1 := Sum_Count ;
Count2 := Sum_Count ;
FOR i := 1 TO Umgebung DO
PROPAGATE .up_port (shift_number1) ; (* sending own pixelvalue to the *)
PROPAGATE .down_port(shift_number2) ; (* right and to the left *)
Sum := Sum + shift_number1 + shift_number2 ; (* and add *)
PROPAGATE .up_port (Count1) ; (* informing about validity of the values *)
PROPAGATE .down_port(Count2) ;
Sum_Count := Sum_Count + Count1 + Count2 ;
END ;
IF Sum_Count > 0 THEN
Sum := Sum / FLOAT(Sum_Count) ;
END ; (* IF Sum_Count > 0 *)
RETURN Sum ;
END Average ;
(************************** Common_Elements *********************************)
(* The vectors LEFT and RIGHT contains in the beginning both images in the *)
(* right position against one another. They would be compared pixelwise and *)
(* the result stored in the vector PIXEL[]. *)
(* Afterwards the left image would be shifted left by one pixel and compared*)
(* again for common elements with the right image. This repeats until *)
(* maxDepth is reached. *)
PROCEDURE Common_Elements ;
SCALAR
plain : INTEGER ;
BEGIN
PARALLEL [ 1 .. PicHeigth ] , [ 1 .. PicWidth ]
FOR plain := 1 TO maxDepth DO (* for each image-plain *)
Pixel[plain] := 0 ;
IF (Left # 0) & (Right # 0) THEN
Pixel[plain] := 1 + ABS( Left-Right) ;
END ; (* IF (Left *)
PROPAGATE .left_port(Left) ;
(* shifting left image one position to the left *)
END ;
ENDPARALLEL ;
END Common_Elements ;
(************************** Search_Objects **********************************)
(* For almost each pixel it exists some possible plains. By comparing with *)
(* neighbour-pixels it can be find out to which plain a pixel belongs. *)
PROCEDURE Search_Objects ;
SCALAR
plain : INTEGER ;
VECTOR
minCount,
minPos : INTEGER ;
min,
PixAverage : REAL ;
BEGIN
PARALLEL [ 1 .. PicHeigth ] , [ 1 .. PicWidth ]
min :=100000.0 ; minPos := 0 ; minCount := 0 ;
FOR plain := 1 TO maxDepth DO (* for each plain *)
PixAverage := Average( FLOAT( Pixel[ plain ]), margin ) ;
IF Pixel[plain] <> 0 THEN (* only if plain is valid *)
Pixel[plain] := 0 ; (* first make plain invalid *)
IF PixAverage = min THEN (* if same minimum found *)
INC( minCount ) ; (* increase numbers of found mimima *)
END ; (* PixAverage = min *)
IF PixAverage < min THEN (* if new miminum found *)
minPos := plain ; (* make this plain valid *)
min := PixAverage ; (* store minimum *)
minCount := 1 ; (* set numbers of found minima to 1 *)
END ; (* IF PixAverage < min *)
END ; (* IF Pixel[plain] <> 0 *)
END ; (* FOR plain *)
IF (minPos > 0) AND (minCount = 1) THEN (* admit only clear minima *)
Pixel[minPos] := 1 ; (* minPos is the valid plain *)
END ;
ENDPARALLEL ;
END Search_Objects ;
(************************* Filter *******************************************)
(* It's possible that some few pixel would not be correct calculated. *)
(* The procedure Filter has to search for these pixels and then assign *)
(* to a suitable plain. *)
PROCEDURE Filter ;
SCALAR
tolerance,
plain,
num_changes : INTEGER ;
VECTOR
previous,
max,
maxpos,
PixelSum : INTEGER ;
change : BOOLEAN ;
BEGIN
WriteString("Filter ...") ; WriteLn ;
tolerance := Filter_iterat;
PARALLEL [ 1 .. PicHeigth ] , [ 1 .. PicWidth ]
REPEAT
max := 0 ; change := FALSE ;
FOR plain := 1 TO maxDepth DO (* for each image-plain *)
PixelSum := ParallelSum3x3( Pixel[plain] ) ;
(* look at 3x3-region neighbourhood *)
IF PixelSum > max THEN
max := PixelSum ; (* store the propably best plain *)
maxpos := plain ;
END ; (* IF PixelSum *)
IF ( Pixel[plain] = 1 ) AND ( PixelSum <= tolerance ) THEN
(* 'lost pixel' ? *)
Pixel[plain] := 0 ;
change := TRUE ;
previous := plain ;
END ; (* IF Pixel[plain] *)
END ; (* FOR plain *)
IF change AND (max > 1) AND (previous <> maxpos) THEN
Pixel[maxpos] := 1 ; (* 'lost pixel' get a new plain *)
END ; (* IF change AND *)
num_changes := REDUCE.SUM( ORD(change) ) ;
DEC( tolerance ) ;
WriteString("Changes : ") ; WriteInt( num_changes , 3 ) ; WriteLn ;
UNTIL (num_changes = 0) OR (tolerance = 0) ;
ENDPARALLEL ;
END Filter ;
(**************** Interpolate_and_Heigthlines ******************************)
(* Interpolate intervalls *)
PROCEDURE Interpolate_and_Heigthlines ;
SCALAR
num_Linien, (* number of heigth-lines which have to *)
(* be draw in *)
num_changes, (* number of executed changes *)
j : INTEGER ; (* loop-variable *)
min_Value, (* minimal heigth-value *)
max_Value, (* maximal heigth-value *)
step : REAL ;
VECTOR
change,
fix : BOOLEAN ; (* fix = TRUE => not allowed to change pixel *)
previous, (* value of previous iteration *)
RHeigth, (* Heigth as real-number *)
medium : REAL ;
(*-------------------------- skip_plain -----------------------------------*)
PROCEDURE skip_plain( SCALAR skipvalue : REAL ) : VECTOR BOOLEAN ;
VECTOR
skip : BOOLEAN ;
Neighbour1,
Neighbour2,
Neighbour3,
Neighbour4 : REAL ;
BEGIN
skip := FALSE ;
PROPAGATE.left_port ( RHeigth , Neighbour1 ) ;
PROPAGATE.right_port( RHeigth , Neighbour2 ) ;
PROPAGATE.up_port ( RHeigth , Neighbour3 ) ;
PROPAGATE.down_port ( RHeigth , Neighbour4 ) ;
IF ( RHeigth <= skipvalue < Neighbour1 ) OR
( RHeigth <= skipvalue < Neighbour2 ) OR
( RHeigth <= skipvalue < Neighbour3 ) OR
( RHeigth <= skipvalue < Neighbour4 ) THEN
skip := TRUE ;
END ;
RETURN skip ;
END skip_plain ;
(*-------------------------------------------------------------------------*)
BEGIN
PARALLEL [ 1 .. PicHeigth ] , [ 1 .. PicWidth ]
fix := Heigth > 0 ;
RHeigth := FLOAT( Heigth ) ;
previous := RHeigth ;
REPEAT
medium := Average( RHeigth , 1 ) ; (* 3x3 pixel size area *)
IF ( NOT fix ) THEN (* all free pixels *)
RHeigth := medium ;
END ; (* IF ( NOT fix ) AND *)
change := ABS( RHeigth-previous) > 0.2 ;
previous := RHeigth ;
num_changes := REDUCE.SUM( ORD(change) ) ;
WriteString("Changes : ") ; WriteInt( num_changes , 3 ) ; WriteLn ;
UNTIL num_changes < 10 ;
WriteString("Smoothing lines ...") ; WriteLn ;
FOR j := 1 TO 5 DO
RHeigth := Average(RHeigth,1) ; (* take average of all pixels *)
END ; (* FOR *)
WriteString("Computing heigth-lines ...") ; WriteLn ;
min_Value := REDUCE.MIN(RHeigth) ;
max_Value := REDUCE.MAX(RHeigth) ;
IF Batch THEN
num_Linien := Number_of_Lines ;
ELSE
WriteString( "Minimum(Heigth) = ") ;
WriteFixPt(min_Value,2,2) ;
WriteString( " , Maximum(Heigth) = ") ;
WriteFixPt(max_Value,2,2) ; WriteLn ;
WriteString( "Number of heigth-lines you want to see : ");
ReadInt( num_Linien ) ;
END ;
step := (max_Value - min_Value) / FLOAT(num_Linien) ;
Heigth := 0 ;
WHILE min_Value < max_Value DO
IF skip_plain( min_Value ) THEN
Heigth := maxDepth ; (* original : 16 *)
END ; (* IF *)
min_Value := min_Value + step ;
END ; (* WHILE *)
ENDPARALLEL ;
END Interpolate_and_Heigthlines ;
(************************* find_vertical_rel_region *************************)
PROCEDURE find_vertical_rel_region ;
CONST
relocationen = 5 ;
SCALAR
quality : ARRAY[-relocationen .. relocationen],[-relocationen .. relocationen] OF INTEGER ;
i,j : INTEGER ;
VECTOR
Buffer : INTEGER ;
BEGIN
WriteString("Computing correction-value for vertical image-position ...");
WriteLn ;
PARALLEL [ 1 .. PicHeigth ] , [ 1 .. PicWidth ]
FOR i := -relocationen TO relocationen DO
Buffer := Left ;
PROPAGATE .right_port^relocationen( Buffer ) ;
IF i # 0 THEN
IF i < 0 THEN
j := -i ;
PROPAGATE .up_port^j( Buffer ) ;
ELSE
PROPAGATE .down_port^i( Buffer ) ;
END ;
END ;
FOR j := -relocationen TO relocationen DO
PROPAGATE .left_port( Buffer ) ;
IF ( 5 < DIM1 < PicHeigth-5 ) AND ( 5 < DIM2 < PicWidth-5 ) THEN
quality[i][j] := REDUCE.SUM( ABS( Buffer-Right )) ;
END ;
END ;
END ;
ENDPARALLEL ;
FOR i := -relocationen TO relocationen DO
FOR j := -relocationen+1 TO relocationen DO
quality[i][-relocationen] := quality[i][-relocationen] + quality[i][j] ;
END ;
END ;
j := -relocationen ;
FOR i := -relocationen+1 TO relocationen DO
IF quality[i][-relocationen] < quality[-relocationen][-relocationen] THEN
quality[-relocationen][-relocationen] := quality[i][-relocationen] ;
j := i ;
END ;
END ;
WriteString("Minimum in line ") ; WriteInt(j,2) ; WriteLn ;
END find_vertical_rel_region ;
(************************* main program *************************************)
BEGIN
(* initialize some variables *)
PARALLEL
FOR counter := 1 TO maxDepth DO
Pixel[counter] := 0 ;
END ;
Heigth := 0 ;
Left := 0 ;
Right := 0 ;
ENDPARALLEL ;
STORE( Left , LeftPicture ) ;
STORE( Right , RightPicture ) ;
counter := 1 ;
(* test, if batch-file exist *)
OpenInput( "realpic.batch" ) ;
IF Done THEN
WriteString(" Program in Batch-Mode ...") ; WriteLn ;
Batch := TRUE ;
ELSE
Batch := FALSE ;
END ;
CloseInput ;
LOOP
IF Batch THEN
OpenInput( "realpic.batch" ) ;
FOR i := 1 TO counter DO
ReadString( InputFile ) ;
ReadString( OutputFile ) ;
ReadInt( RegionX ) ;
ReadInt( RegionY ) ;
ReadInt( Number_of_Lines ) ;
END ; (* FOR i := 1 *)
INC( counter ) ;
IF NOT Done THEN
WriteString( " ********* END ******** " ) ; WriteLn ;
HALT ;
END ; (* IF NOT Done *)
END ; (* IF Batch *)
CloseInput ;
IF ReadPicture() = FALSE THEN
WriteString("###### Program terminated abnormaly ######" ) ;
WriteLn ; HALT ;
END ;
CloseInput ; (* return to input from console *)
LOAD( Left , LeftPicture ) ;
LOAD( Right , RightPicture ) ;
PARALLEL [ 1 .. PicHeigth ] , [ 1 .. PicWidth ]
Left := Search_Edge( Left ) ;
Heigth := Left ;
ENDPARALLEL ;
Show_All ;
PARALLEL [ 1 .. PicHeigth ] , [ 1 .. PicWidth ]
Right := Search_Edge( Right ) ;
Heigth := Right ;
ENDPARALLEL ;
Show_All ;
WriteString( "Examine left and right image for common elements ...") ;
WriteLn ;
Common_Elements ;
Show_Plains ;
WriteString("Discovering objects in each plain ...") ; WriteLn ;
Search_Objects ; (* find for each pixel the right plain *)
Compute_Heigth ;
Show_Plains ;
Show_All ;
Filter ;
Compute_Heigth ;
Show_Plains ;
Show_All ;
(* saving resulting image in PPM-format *)
IF NOT Batch THEN
WriteString( "Outputfile (without extension '.h.ppm' und '.f.ppm' ) : " ) ;
(* requesting filename *)
ReadString( OutputFile ) ;
END ;
FileName := strcat( OutputFile , ".f.ppm" ) ;
WriteString( "Saving resulting image as '") ;
WriteString( FileName ) ;
WriteString("' ..." ) ; WriteLn ;
PPM_Output ;
WriteString("Interpolating and computing heigth-lines ...") ; WriteLn ;
Interpolate_and_Heigthlines ;
Show_All ;
FileName := strcat( OutputFile , ".h.ppm" ) ;
WriteString( "Saving interpolated image as '") ;
WriteString( FileName ) ;
WriteString("' ..." ) ; WriteLn ;
PPM_Output ;
IF Batch THEN
CloseOutput ;
ELSE
HALT ;
END ;
END (* LOOP *)
END Evaluation_of_real_Random_Stereo_Images .